/* 
 * File:   server_Grafico.h
 * Author: nahuel
 *
 * Created on June 12, 2013, 7:24 PM
 */

#ifndef GRAFICO_H
#define	GRAFICO_H

#include <gtkmm-3.0/gtkmm/drawingarea.h>
#include <gtkmm-3.0/gtkmm/builder.h>
#include <list>
#include <time.h>


typedef struct {
    double x;
    double y;
} DataPoint;

class Grafico : public Gtk::DrawingArea {
    private:
        Gtk::DrawingArea* _drawingArea;
        unsigned int _refreshRate;  // En segundos
        std::list<DataPoint*> _listDatos;
        std::string _pathAuServidor;
        time_t _startTime;
        
        
        void ReadNewDataPoint();
        
        std::string XAxisFormatter(double x);
        std::string YAxisFormatter(double y);        
        
        void WriteXAxisLabel(const Cairo::RefPtr<Cairo::Context>& cr, const std::string& label, double x, double y);
        void WriteYAxisLabel(const Cairo::RefPtr<Cairo::Context>& cr, const std::string& label, double x, double y);
        
        std::string GetXAxisLabel(unsigned int i, double maxX, double minX);
        std::string GetYAxisLabel(unsigned int i, double maxY, double minY);
        
        double TransformX(double transformThis, double xAxisBeg, double xAxisEnd, double minX, double maxX);
        double TransformY(double transformThis, double yAxisBeg, double yAxisEnd, double minY, double maxY);        
        
    protected:
        virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
        bool on_timeout();
        
    public:
        Grafico(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade);
        virtual ~Grafico();
};

#endif	/* GRAFICO_H */

